package com.atguigu.commonutils;


import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * 统一返回类
 * @author: He Wentao
 * @date: 2022/8/13 20:43
 */
@Data
public class R {
    @ApiModelProperty(value = "是否成功")
    private Boolean success;

    @ApiModelProperty(value = "返回码")
    private Integer code;

    @ApiModelProperty(value = "返回消息")
    private String message;

    @ApiModelProperty(value = "返回数据")
    private Map<String,Object> data = new HashMap<>();

    private R(){}

    private R(Boolean success, Integer code, String message) {
        this.success = success;
        this.code = code;
        this.message = message;
    }
    // 快速成功
    public static R ok(){
        return new R(true,ResultCode.SUCCESS.getValue(),"成功");
    }
    // 快速失败
    public static R error(){
        return new R(false,ResultCode.ERROR.getValue(),"失败");
    }

    // 添加数据
    public  R data(String key,Object value){
        this.data.put(key,value);
        return this;
    }

    // 添加数据
    public  R data(Map<String,Object> map){
        this.setData(map);
        return this;
    }

    // 更改描述信息
    public R message(String mes){
        this.setMessage(mes);
        return this;
    }

    // 更改状态码
    public R coed(Integer code){
        this.setCode(code);
        return this;
    }



}
